package com.wasu;

import android.content.Context;
import com.wasu.constant.Config;
import com.wasu.doicommon.util.AppCheckUtils;
import com.wasu.doicommon.util.SharedPreferenceHelper;
import com.wasu.livedata.library.BuildConfig;
import com.wasu.ngb.PlayerManager;
import com.wasu.sdk_ott.receiver.LiveChannelAuthHelper;
import com.wasu.sdk_ott.utils.AppInitHelper;
import com.wasu.sdk_ott.utils.WasuTvModelUtil;

public class UILApplication {
    private static volatile UILApplication instance;
    private Context context;

    private UILApplication() {
    }

    public void init(Context context) {
        this.context = context;
        PlayerManager.init(context);
        loadConfigData();
        new Thread(new Runnable() {
            @Override
            public void run() {
                AppInitHelper.INSTANCE.appInit(context);
                LiveChannelAuthHelper.updateChannel(context);
            }
        }).start();

    }

    public static UILApplication getInstance() {
        if (instance == null) {
            synchronized (UILApplication.class) {
                if (instance == null) {
                    instance = new UILApplication();
                }
            }
        }
        return instance;
    }

    public Context getApplication() {
        return context;
    }

    /**
     * 读取本地缓存，配置
     */
    public void loadConfigData() {
        String settings_net_type = SharedPreferenceHelper.getInstance(getApplication(), Config.SP_FILE_NAME).load("settings_net_type", "");
        if ("IP".equals(settings_net_type)) {
            WasuTvModelUtil.setbIpMode(true);
        } else {
            WasuTvModelUtil.setbIpMode(false);
        }
        SharedPreferenceHelper authPreference = SharedPreferenceHelper.getInstance(getApplication(), Config.PREFERENCE_NAME);
        Config.sUserId =authPreference.load("UserId", "");
        Config.sUserProfile =authPreference.load("UserProfile", "");

        //todo LC 数据获取，单独APK运行写死
        if (BuildConfig.DEBUG) {
            AppCheckUtils.setTvType("true");
            WasuTvModelUtil.setbIpMode(true);
            WasuTvModelUtil.setbIpMode(true);
            Config.sUserId = "990000017676193";
            Config.sUserProfile = "01#4001#47014421#1-571-57101-17519-35000290-35101084-145858561-1000062241##";
        }
    }


}
